﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DaInterFace;
using DaInterFace.PDA;
using DaInterFace.PDA.P02;

namespace P02
{
    /// <summary>
    /// A09 查询订单下是否存在采样单
    /// </summary>
    public class A09 : IPDAChild
    {
        public void Code(IPDA handler, CodeResult CR, PDACodeUser user, String parameter)
        {
            P02A09P P = (P02A09P)handler.SerialApi.Deserialize(typeof(P02A09P), parameter, CR.SerialType);
            P02A09R R = new P02A09R();
            try
            {
                Recordset rs = handler.Data.ExeProcedure(P.BaseNo, String.Format("SELECT FBillNo FROM KEW_PurchSampling WHERE FCheckBox=0 AND FID_SRC1={0}", Common.FilterSql(P.OrderID)));

                if (rs.Enable)
                {
                    if (rs.Data.Tables[0].Rows.Count > 0)
                    {
                        CR.Result = EnumResult.Normal;
                        CR.Message = "订单下已经存在采样单。";
                        
                        R.IsExist = true;
                        R.SampNo = rs.Data.Tables[0].Rows[0]["FBillNo"].ToString();
                    }
                    else 
                    {
                        CR.Result = EnumResult.Normal;
                        CR.Message = "";
                        R.IsExist = false;
                    }

                    CR.Content = handler.SerialApi.Serializer(typeof(P02A09R), R, CR.SerialType);
                }
                else
                {
                    CR.Result = EnumResult.Error;
                    CR.Message = "数据库错误";
                    R.IsExist = false;
                }
            }
            catch (Exception ex)
            {
                CR.Result = EnumResult.Error;
                CR.Message = String.Format("发生错误:{0}", ex.Message);
            }
        }
    }


}
